﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using DLL;
using BLL;

namespace WebApplication2
{
    public partial class WebForm6 : System.Web.UI.Page
    {
        BLLShort bl = new BLLShort();
        //ShortCarShare sc = new ShortCarShare();
        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!IsPostBack)
            {
                InquiryAdde();
                ShortCarShare sc = new ShortCarShare();
                sc.SGoCity = txtaddress1.Text;
                sc.SDesitionation = txtaddress2.Text;
                Info(sc);
            }

            //城市选择
            SelectListCity.DataSource = LongSortBLL.SearchCity();
            SelectListCity.DataTextField = "CtName";
            SelectListCity.DataValueField = "CtID";
            SelectListCity.DataBind();
        }
        //查询拼车信息
        public void Info(ShortCarShare sc)
        {
            var dt = bl.DataTable(sc);
            ShortGridView.DataSource = dt;
            ShortGridView.DataBind();


        }
        //获取查询地址
        private void InquiryAdde()
        {
            string SGoCity = Request.QueryString["SGoCity"];
            string SDesitionation = Request.QueryString["SDesitionation"];
            txtaddress1.Text = SGoCity;
            txtaddress2.Text = SDesitionation;
        }
        protected void BtnSdd_Click(object sender, EventArgs e)
        {
            if (txtaddress1.Text.Length == 0)
            {
                Label1.Text = "不能为空！";
                return;
            }
            if (txtaddress2.Text.Length == 0)
            {
                Label2.Text = "不能为空！";
                return;
            }
            string SGoCity = txtaddress1.Text.Trim();
            string SDesitionation = txtaddress2.Text.Trim();
            Response.Write($"<script>location.href='Commuting-SonTwo.aspx?SGoCity={SGoCity}&&SDesitionation={SDesitionation}';</script>");


            

        }

        //发布上下班拼车
        protected void ButRelease_Click(object sender, EventArgs e)
        {
            if (start.Text.Length != 0 && end.Text.Length != 0 &&txtModel.Text.Length!=0)
            {
                ShortCarShare sc = new ShortCarShare();
                //string str = ",";
                string strT = ":";
                string day= $"{Request.Form["daySelect"].ToString()}";
                string time = $"{Request.Form["timeSelect"].ToString()}";
                string minute = $"{Request.Form["minuteSelect"].ToString()}";

                sc.UserID = "13558365701";
                sc.SPType = "车主";
                sc.SStatus = "等待中";
                sc.SPTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                sc.SGoCity = start.Text.Trim();
                sc.SDesitionation = end.Text.Trim();
                //sc.SPass = TextBox3.Text += str += TextBox4.Text += str += TextBox5.Text += str += TextBox6.Text;
                sc.SPass = TextBox3.Text += TextBox4.Text += TextBox5.Text += TextBox6.Text;
                sc.SReturn = $"{Request.Form["returnSelect"].ToString()}";
                
                sc.SCWord = txtExplain.Text.Trim();
                sc.SCarType = $"{Request.Form["carType"].ToString()}";
                sc.SContain = int.Parse(txtModel.Text.Trim());
                sc.SCost = int.Parse(txtMode2.Text.Trim());
                sc.SGoTime =day+= strT +=time += strT +=minute;
                if (LongSortBLL.SAdd(sc)>0)
                {
                    ButRelease.Attributes.Add("onclick", "return confirm('发布成功！');");
                }
                else
                {
                    ButRelease.Attributes.Add("onclick", "return confirm('发布失败！');");
                }
                
            }
            else
            {
                ButRelease.Attributes.Add("onclick", "return confirm('请输入完整信息！');");
            }

        }
        protected void SelectListCity_SelectedIndexChanged(object sender, EventArgs e)
        {
         
        }

        protected void ShortGridView_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.ToLower()=="det")
            {
                string id = e.CommandArgument.ToString();
                Response.Redirect($"Commuting-Son.aspx?id={id}");
            }
        }
    }
}